import {
  Inject,
  Controller,
  Get,
  Post,
  Body,
  Queries,
  Query,
  Del,
  Param,
  Put
} from "@midwayjs/core";
import { Context } from "@midwayjs/koa";
import { DeskService } from "../service/desk.service";
import { ApiTags } from "@midwayjs/swagger";
import { Utils } from "../utils/index";
import {
  DeskCreateDto,
  DeskListQueryDto,
  DeskPageQueryDto
} from "../dto/desk.dto";

@ApiTags("球桌管理")
@Controller()
export class DeskController {
  @Inject()
  ctx: Context;

  @Inject()
  deskService: DeskService;

  @Inject()
  utils: Utils;

  @Get("/auth-api/desk-type-list", { summary: "获取球桌类型列表" })
  async get_desk_type_list() {
    const findRes = await this.deskService.get_desk_type_list();
    return this.utils.response.success(findRes);
  }

  @Get("/auth-api/brand-list", { summary: "获取品牌列表" })
  async get_brand_list() {
    const findRes = await this.deskService.get_brand_list();
    return this.utils.response.success(findRes);
  }

  @Post("/auth-api/desk", { summary: "添加球桌" })
  async add_desk(@Body() deskCreateDto: DeskCreateDto) {
    return this.utils.response.success(
      await this.deskService.add_desk(deskCreateDto)
    );
  }

  @Put("/auth-api/desk/:deskId", { summary: "修改球桌" })
  async update_desk(
    @Param("deskId") deskId: string,
    @Body() updateDto: DeskCreateDto
  ) {
    return this.utils.response.success(
      await this.deskService.update_desk(deskId, updateDto)
    );
  }

  @Del("/auth-api/desk/:deskId", { summary: "删除球桌" })
  async remove_desk(@Param("deskId") deskId: string) {
    return this.utils.response.success(
      await this.deskService.remove_desk(deskId)
    );
  }

  @Get("/auth-api/desk/:deskId", { summary: "获取球桌详情" })
  async get_desk(@Param("deskId") deskId: string) {
    return this.utils.response.success(await this.deskService.get_desk(deskId));
  }

  @Get("/auth-api/desk/list")
  async get_desk_list(@Queries() queryDto: DeskListQueryDto) {
    return this.utils.response.success(
      await this.deskService.get_desk_list(queryDto)
    );
  }

  @Get("/auth-api/desk/page")
  async get_desk_page_list(@Queries() pageDto: DeskPageQueryDto) {
    pageDto.current = pageDto.current
      ? pageDto.current
      : this.ctx.request.query.current + "";

    pageDto.pageSize = pageDto.pageSize
      ? pageDto.pageSize
      : this.ctx.request.query.pageSize + "";

    return this.utils.response.success(
      await this.deskService.get_desk_page_list(pageDto)
    );
  }

  @Get("/common-api/desk/:deskId", { summary: "获取球桌详情" })
  async get_wxapp_desk(@Param("deskId") deskId: string) {
    return this.utils.response.success(await this.deskService.get_desk(deskId));
  }

  @Get("/common-api/desk/page")
  async get_wxapp_desk_page_list(@Query("brandId") brandId: string) {
    return this.utils.response.success(
      await this.deskService.get_wxapp_desk_page_list(brandId || "")
    );
  }
}
